<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>EventSource流</title>
</head>
<body>
<div id="clock">

</div>
<script>
  const eventSource = new EventSource('/clock');
  const clock = document.querySelector('#clock');

  // 监听服务器发过来的消息
  eventSource.onmessage = function (event) {
    const message = event.data;
    clock.innerHTML = message;
  };

  // 监听连接请求失败的错误事件
  eventSource.onerror = function(event){

  }
</script>
</body>
</html>
